package com.datamation.swadeshi.view;

import java.util.ArrayList;

import com.datamation.swadeshi.R;
import com.datamation.swadeshi.adapter.NonPrdDetails;
import com.datamation.swadeshi.adapter.NonPrdHeader;
import com.datamation.swadeshi.control.ReferenceNum;
import com.datamation.swadeshi.control.data.FDaynPrdHedDS;
import com.datamation.swadeshi.control.data.fDaynPrdDetDS;
import com.datamation.swadeshi.model.FDaynPrdHed;
import com.datamation.swadeshi.model.FTranDet;

import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.SearchView.OnQueryTextListener;

public class FragmentNonProductiveMain extends Fragment {
	View view;
	ListView lv_invent_load;
	ArrayList<FDaynPrdHed> loadlist;
	ReferenceNum referenceNum;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		view = inflater.inflate(R.layout.non_productive_main, container, false);
		setHasOptionsMenu(true);
		referenceNum = new  ReferenceNum(getActivity());
		fatchData();
		return view;
	}
	
	@Override
	public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
		
		for(int i = 0; i < menu.size(); ++i){
			menu.removeItem(menu.getItem(i).getItemId());
		}
		
		inflater.inflate(R.menu.frag_nonprd_menu, menu);
		SearchView searchView = (SearchView) menu.findItem(R.id.action_customer_search_phone).getActionView();
		searchView.setOnQueryTextListener(new OnQueryTextListener() {
			
			@Override
			public boolean onQueryTextSubmit(String query) {
				return false;
			}
			
			@Override
			public boolean onQueryTextChange(String newText) {

				return false;
			}
		});
		
	
		super.onCreateOptionsMenu(menu, inflater);
	}
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if(item.getItemId() == R.id.action_nonprd_phone_new)
		{
			FragmentTransaction transaction = getFragmentManager().beginTransaction();
			transaction.replace(R.id.frame_container, new FragmentNonProductiveCall());
			transaction.addToBackStack(null);
			transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
			transaction.commit();
		}
		return super.onOptionsItemSelected(item);
	}
	public void fatchData()
	{
		try {
			MainActivity activity =(MainActivity) getActivity();
			lv_invent_load = (ListView) view.findViewById(R.id.lvPhonenonphedlist);

			FDaynPrdHedDS detDS = new FDaynPrdHedDS(getActivity());
			loadlist = detDS.getAllnonprdHedDetails();
			lv_invent_load.setAdapter(new NonPrdHeader(getActivity(), loadlist));
		}catch (NullPointerException e){
			Log.v("Loading Error", e.toString());
		}
	}

}
